package org.example.seat_management.Service.Impl;

import org.example.seat_management.Entity.SeatInfo;
import org.example.seat_management.Mapper.SeatInfoMapper;
import org.example.seat_management.Service.SeatService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SeatServiceImpl implements SeatService {

    private final SeatInfoMapper seatInfoMapper;

    public SeatServiceImpl(SeatInfoMapper seatInfoMapper) {
        this.seatInfoMapper = seatInfoMapper;
    }

    @Override
    @Transactional
    public void batchInitialize(List<SeatInfo> seats) {
        if (seats == null || seats.isEmpty()) {
            return;
        }
        seatInfoMapper.batchUpsert(seats);
    }

    @Override
    @Transactional
    public void upsert(SeatInfo seatInfo) {
        seatInfoMapper.upsert(seatInfo);
    }

    @Override
    @Transactional
    public void update(SeatInfo seatInfo) {
        seatInfoMapper.update(seatInfo);
    }

    @Override
    @Transactional
    public void deleteById(Long id) {
        seatInfoMapper.softDeleteById(id);
    }

    @Override
    public SeatInfo getByPosition(Long classroomId, String section, Integer columnIndex, Integer rowIndex) {
        return seatInfoMapper.findByPosition(classroomId, section, columnIndex, rowIndex);
    }

    @Override
    public List<SeatInfo> listByClassroom(Long classroomId) {
        return seatInfoMapper.listByClassroom(classroomId);
    }

    @Override
    @Transactional
    public void batchUpsert(List<SeatInfo> seats) {
        if (seats == null || seats.isEmpty()) {
            return;
        }
        seatInfoMapper.batchUpsert(seats);
    }
}


